# config/app_config.py

import os
from datetime import timedelta

class BaseConfig:
    """基础配置类"""
    HELLO_PROM = 'hello world'
    
    # 数据库配置基础设置
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    
    # JWT配置
    JWT_SECRET_KEY = os.getenv('JWT_SECRET_KEY', 'super-secret')  # 建议在生产环境中通过环境变量设置
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1)
    
    # Session配置
    SESSION_TYPE = 'none'  # 手动管理 session

class DevelopmentConfig(BaseConfig):
    """开发环境配置"""
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = os.getenv(
        'DEV_DATABASE_URL',
        'mysql+pymysql://root:123456@localhost/example'
    )
    # 开发环境特定配置
    CORS_HEADERS = 'Content-Type'
    ENV = 'development'

class TestingConfig(BaseConfig):
    """测试环境配置"""
    TESTING = True
    SQLALCHEMY_DATABASE_URI = os.getenv(
        'TEST_DATABASE_URL',
        'mysql+pymysql://root:123456@127.0.0.1/example_test'
    )
    # 测试环境特定配置
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(minutes=5)
    ENV = 'testing'

class ProductionConfig(BaseConfig):
    """生产环境配置"""
    DEBUG = False
    SQLALCHEMY_DATABASE_URI = os.getenv(
        'PROD_DATABASE_URL',
        'mysql+pymysql://root:123456@127.0.0.1/example_prod'
    )
    # 生产环境特定配置
    JWT_SECRET_KEY = os.getenv('JWT_SECRET_KEY')  # 必须通过环境变量设置
    SESSION_COOKIE_SECURE = True
    SESSION_COOKIE_HTTPONLY = True
    ENV = 'production'

# 配置映射
config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}